@extends('admin.layouts.base')

@section('title','控制面板')

@section('pageHeader','控制面板')

@section('pageDesc','DashBoard')

@section('content')

    <div class="row page-title-row" style="margin:5px;">
        <div class="col-md-6">
        </div>
        <div class="col-md-6 text-right">
			<a href="javascript:;" onclick="updateGroupTels()" class="btn btn-default btn-retweet">
                <i class="fa-exchange"></i> 批量更新模板
            </a>
            <a href="/admin/group/create" class="btn btn-success btn-md">
                <i class="fa fa-plus-circle"></i> 添加分组
            </a>
        </div>
    </div>
    <div class="row page-title-row" style="margin:5px;">
        <div class="col-md-6">
        </div>
        <div class="col-md-6 text-right">
        </div>
    </div>

    <div class="row">
        <div class="col-xs-12">
            <div class="box">

                @include('admin.partials.errors')
                @include('admin.partials.success')
                <div class="box-body">
                    <table id="tags-table" class="table table-bordered table-hover">
                        <thead>
                        <tr>
                            <th data-sortable="false" class="hidden-sm "><input id="all" type="checkbox">
                                    全选&nbsp;&nbsp; <a href="#" onclick="batchDel()" class="text-danger">删除</a>
                            </th>
                            <th data-sortable="false" class="hidden-sm">序号</th>
                            <th class="hidden-sm">所属用户</th>
                            <th class="hidden-sm">分组名</th>
                            <th class="hidden-sm">分组目录</th>
                            <th class="hidden-md">跳转类型</th>
                            <th class="hidden-md">跳转目标</th>
                            <th class="hidden-md">模板</th>
                            <th class="hidden-md">修改日期</th>
                            <th data-sortable="false">操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
    </div>
    </div>
    <div class="modal fade" id="modal-delete" tabIndex="-1">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">
                        ×
                    </button>
                    <h4 class="modal-title">提示</h4>
                </div>
                <div class="modal-body">
                    <p class="lead">
                        <i class="fa fa-question-circle fa-lg"></i>
                        确认要删除这个分组吗?
                    </p>
                </div>
                <div class="modal-footer">
                    <form class="deleteForm" method="POST" action="/admin/group">
                        <input type="hidden" name="_token" value="{{ csrf_token() }}">
                        <input type="hidden" name="_method" value="DELETE">
                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                        <button type="submit" class="btn btn-danger">
                            <i class="fa fa-times-circle"></i>确认
                        </button>
                    </form>
                </div>

            </div>
        </div>
    </div>
    {{--批量删除--}}
    <div class="modal fade" id="modal-batch-del" tabIndex="-1">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">
                        ×
                    </button>
                    <h4 class="modal-title">提示</h4>
                </div>
                <div class="modal-body">
                    <p class="lead">
                        <i class="fa fa-question-circle fa-lg"></i>
                        确认要删除这些分组吗?
                    </p>
                </div>
                <div class="modal-footer">
                    <form class="batchDelForm" method="POST" action="/admin/group">
                        <input type="hidden" name="_token" value="{{ csrf_token() }}">
                        <input type="hidden" name="_method" value="DELETE">
                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                        <button type="submit" class="btn btn-danger">
                            <i class="fa fa-times-circle"></i>确认
                        </button>
                    </form>
                </div>

            </div>
        </div>
    </div>
@stop

@section('js')

    <script>
        $(function () {
            var table = $("#tags-table").DataTable({
                language: {
                    "sProcessing": "处理中...",
                    "sLengthMenu": "显示 _MENU_ 项结果",
                    "sZeroRecords": "没有匹配结果",
                    "sInfo": "显示第 _START_ 至 _END_ 项结果，共 _TOTAL_ 项",
                    "sInfoEmpty": "显示第 0 至 0 项结果，共 0 项",
                    "sInfoFiltered": "(由 _MAX_ 项结果过滤)",
                    "sInfoPostFix": "",
                    "sSearch": "搜索:",
                    "sUrl": "",
                    "sEmptyTable": "表中数据为空",
                    "sLoadingRecords": "载入中...",
                    "sInfoThousands": ",",
                    "oPaginate": {
                        "sFirst": "首页",
                        "sPrevious": "上页",
                        "sNext": "下页",
                        "sLast": "末页"
                    },
                    "oAria": {
                        "sSortAscending": ": 以升序排列此列",
                        "sSortDescending": ": 以降序排列此列"
                    }
                },
                "iDisplayLength": 100,
                order: [[1, "desc"]],
                serverSide: true,
                ajax: {
                    url: '/admin/group/index',
                    type: 'POST',
                    headers: {
                        'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
                    }
                },
                "columns": [
                    {"data": "action"},
                    {"data": "id"},
                    {"data": "username"},
                    {"data": "title"},
                    {"data": "directory"},
                    {"data": "go_to_type_title"},
                    {"data": "target_gname"},
                    {"data": "template"},
                    {"data": "updated_at"},
                    {"data": "action"}
                ],
                columnDefs: [
                    {
                        'targets': -1, "render": function (data, type, row)
                        {
                            var caozuo = '<a style="margin:3px;" href="/admin/group/' + row['id'] + '/edit" class="X-Small btn-xs text-success "><i class="fa fa-edit"></i> 编辑</a>';
                            caozuo += '<a style="margin:3px;" href="javascript:;" onclick="updateGroupTel(\''+row['id']+'\')" class="X-Small btn-xs text-success" title="更新所属分组模板"><i class="fa fa-edit"></i> 更新模板</a>';
                            caozuo += '<a style="margin:3px;" href="#" attr="' + row['id'] + '" class="delBtn X-Small btn-xs text-danger "><i class="fa fa-times-circle-o"></i> 删除</a>';
                            caozuo += '<a style="margin:3px;" href="/admin/groupAttr?gid=' + row['id'] + '" class="X-Small btn-xs text-warning "> 属性列表</a>';
                            caozuo += '<a style="margin:3px;" href="/admin/domain?gid=' + row['id'] + '" class="X-Small btn-xs text-primary"> 域名列表</a>';
                            return caozuo;
                        }
                    },
                    {
                        'targets': 0, "render": function (data, type, row)
                        {
                            var caozuoCB = '<div class="checkbox hidden-sm"><label><input class="itemCB" name="itemCB[]" type="checkbox" value="' + row['id'] + '"></label></div>';
                            return caozuoCB;
                        }
                    }
                ]
            });

            table.on('preXhr.dt', function () {
                loadShow();
            });

            table.on('draw.dt', function () {
                loadFadeOut();
            });

            table.on('order.dt search.dt', function () {
                table.column(1, {search: 'applied', order: 'applied'}).nodes().each(function (cell, i) {
                    cell.innerHTML = i + 1;
                });
            }).draw();

            $("table").delegate('.delBtn', 'click', function () {
                var id = $(this).attr('attr');
                $('.deleteForm').attr('action', '/admin/group/' + id);
                $("#modal-delete").modal();
            });

        });
    </script>
@stop